load("//bazel:mongo_src_rules.bzl", "idl_generator", "mongo_cc_benchmark", "mongo_cc_library", "mongo_cc_unit_test")

package(default_visibility = ["//visibility:public"])

exports_files(
    glob([
        "*.h",
        "*.cpp",
    ]),
)

mongo_cc_library(
    name = "sort_executor",
    srcs = [
        "sort_executor.cpp",
        "sort_key_comparator.cpp",
    ],
    hdrs = [
        "sort_executor.h",
        "sort_key_comparator.h",
    ],
    deps = [
        ":working_set",
        "//src/mongo/db/query:sort_pattern",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db/query:spill_util",
        "//src/mongo/db/sorter:sorter_base",
        "//src/mongo/db/sorter:sorter_stats",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db/storage:encryption_hooks",
        "//src/mongo/db/storage:storage_options",  # TODO(SERVER-93876): Remove.
        "//src/third_party/snappy",
    ],
)

mongo_cc_library(
    name = "js_function",
    srcs = [
        "js_function.cpp",
    ],
    hdrs = [
        "js_function.h",
    ],
    deps = [
        "//src/mongo/db:service_context",
        "//src/mongo/db/auth",
        "//src/mongo/db/query:query_knobs",
        "//src/mongo/scripting:scripting_common",
    ],
)

filegroup(
    name = "headers",
    srcs = [
        "batched_delete_stage.h",
        "batched_delete_stage_buffer.h",
        "delete_stage.h",
        "requires_collection_stage.h",
        "write_stage_common.h",
    ],
)

# WorkingSet target and associated test
mongo_cc_library(
    name = "working_set",
    srcs = [
        "working_set.cpp",
    ],
    hdrs = [
        "working_set.h",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db:service_context",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db/exec/document_value",
        "//src/mongo/db/query/bson:dotted_path_support",
    ],
)

idl_generator(
    name = "batched_delete_stage_gen",
    src = "batched_delete_stage.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
    ],
)

idl_generator(
    name = "disk_use_options_gen",
    src = "disk_use_options.idl",
)

mongo_cc_library(
    name = "scoped_timer",
    srcs = [
        "scoped_timer.cpp",
    ],
    hdrs = [
        "scoped_timer.h",
    ],
    deps = [
        "//src/mongo/db:service_context",
        "//src/mongo/util/net:network",
    ],
)

mongo_cc_library(
    name = "bucket_unpacker",
    srcs = [
        "//src/mongo/db/exec/timeseries:bucket_unpacker.cpp",
    ],
    hdrs = [
        "//src/mongo/db/exec/timeseries:bucket_unpacker.h",
    ],
    deps = [
        "//src/mongo/bson/column",
        "//src/mongo/db:query_expressions",
        "//src/mongo/db/exec/document_value",
        "//src/mongo/db/query:bucket_predicate_generator",
    ],
)

mongo_cc_library(
    name = "projection_executor",
    srcs = [
        "add_fields_projection_executor.cpp",
        "exclusion_projection_executor.cpp",
        "inclusion_projection_executor.cpp",
        "projection_executor_builder.cpp",
        "projection_executor_utils.cpp",
        "projection_node.cpp",
        "//src/mongo/base:exact_cast.h",
        "//src/mongo/db/query:projection_ast_path_tracking_visitor.h",
    ],
    hdrs = [
        "add_fields_projection_executor.h",
        "exclusion_projection_executor.h",
        "inclusion_projection_executor.h",
        "projection_executor_builder.h",
        "projection_executor_utils.h",
        "projection_node.h",
    ],
    deps = [
        "//src/mongo/db:query_expressions",
    ],
)

mongo_cc_library(
    name = "stagedebug_cmd",
    srcs = [
        "stagedebug_cmd.cpp",
    ],
    deps = [
        "//src/mongo/db:query_exec",
        "//src/mongo/db/commands:test_commands_enabled",
        "//src/mongo/db/index:index_access_method",
    ],
)

mongo_cc_library(
    name = "query_shard_server_test_fixture",
    srcs = [
        "query_shard_server_test_fixture.cpp",
    ],
    hdrs = [
        "query_shard_server_test_fixture.h",
    ],
    deps = [
        "//src/mongo/db/pipeline:expression_context_for_test",
        "//src/mongo/db/query:query_test_service_context",
        "//src/mongo/db/s:shard_server_test_fixture",
    ],
)

mongo_cc_unit_test(
    name = "db_exec_test",
    srcs = [
        "add_fields_projection_executor_test.cpp",
        "bucket_unpacker_test.cpp",
        "distinct_scan_test.cpp",
        "exclusion_projection_executor_test.cpp",
        "find_projection_executor_test.cpp",
        "inclusion_projection_executor_test.cpp",
        "orphan_chunk_skipper_test.cpp",
        "projection_executor_builder_test.cpp",
        "projection_executor_redaction_test.cpp",
        "projection_executor_test.cpp",
        "projection_executor_utils_test.cpp",
        "projection_executor_wildcard_access_test.cpp",
        "queued_data_stage_test.cpp",
        "sort_test.cpp",
        "spool_test.cpp",
        "working_set_test.cpp",
        "//src/mongo/db/exec/document_value:document_comparator_test.cpp",
        "//src/mongo/db/exec/document_value:document_metadata_fields_test.cpp",
        "//src/mongo/db/exec/document_value:document_value_test.cpp",
        "//src/mongo/db/exec/document_value:document_value_test_util_self_test.cpp",
        "//src/mongo/db/exec/document_value:value_comparator_test.cpp",
    ],
    tags = ["mongo_unittest_second_group"],
    deps = [
        ":projection_executor",
        ":query_shard_server_test_fixture",
        ":working_set",
        "//src/mongo:base",
        "//src/mongo/bson/column",
        "//src/mongo/db:query_exec",
        "//src/mongo/db:record_id_helpers",
        "//src/mongo/db:service_context_d_test_fixture",
        "//src/mongo/db/auth:authmocks",
        "//src/mongo/db/exec/document_value",
        "//src/mongo/db/exec/document_value:document_value_test_util",
        "//src/mongo/db/pipeline:aggregation_context_fixture",
        "//src/mongo/db/query:query_test_service_context",
        "//src/mongo/db/query/collation:collator_factory_mock",
        "//src/mongo/db/query/collation:collator_interface_mock",
        "//src/mongo/db/timeseries:bucket_compression",
        "//src/mongo/dbtests:mocklib",
        "//src/mongo/idl:server_parameter_test_util",
        "//src/mongo/util:clock_source_mock",
    ],
)

mongo_cc_benchmark(
    name = "distinct_scan_bm",
    srcs = [
        "distinct_scan_bm.cpp",
        "//src/mongo/db:profiler_bm_fixture.h",
    ],
    deps = [
        ":query_shard_server_test_fixture",
        "//src/mongo/db:query_exec",
        "//src/mongo/db:service_context_d_test_fixture",
    ],
)
